package leetcode

type ListNode struct {
	Val  int
	Next *ListNode
}

func getIntersectionNode(headA, headB *ListNode) *ListNode {
	aPtr, bPtr := headA, headB
	for aPtr != bPtr {
		if aPtr == nil {
			aPtr = headB
		} else {
			aPtr = aPtr.Next
		}

		if bPtr == nil {
			bPtr = headA
		} else {
			bPtr = bPtr.Next
		}
	}
	return aPtr
}
